﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COM;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;

namespace DAL
{
    public class OrderBagDAL
    {
        public static void MoveHistoryData()
        {
            List<int> orderBagIdList = new List<int>();
            int orderBagCompletedStatus = (int)OrderBagStatus.Completed;
            int orderBagDelStatus = (int)OrderBagStatus.Deleted;
            DateTime OneHourBegforDT = DateTime.Now.AddHours(-1);
            using (newSampleYPDBEntities db = new newSampleYPDBEntities())
            {
                orderBagIdList = db.Tb_OrderBag.Where(b => (b.Status == orderBagCompletedStatus ||b.Status ==orderBagDelStatus) && b.CompleteTime <= OneHourBegforDT).Select(b => b.OrderBagId).ToList();
            }
            try
            {
                Database db = null;
                db = DatabaseFactory.CreateDatabase();
                DbCommand cmd = db.GetStoredProcCommand("MoveHistoryData");
                cmd.CommandTimeout = 600;
                foreach (var orderBagId in orderBagIdList)
                {
                    db.AddInParameter(cmd, "@orderBagId", DbType.Int32, orderBagId);
                    db.ExecuteNonQuery(cmd);
                    cmd.Parameters.RemoveAt("@orderBagId");
                }
            }
            catch (Exception ex)
            {
                COM.WriteLogForCheck.WriteLogFile(DateTime.Now + "在移动历数据时出错：" + ex.Message);
            }
        }
    }
}
